package com.ruihu.admin.module.business.electric.config.controller;

import com.ruihu.admin.common.anno.OperateLog;
import com.ruihu.admin.common.domain.PageResultDTO;
import com.ruihu.admin.common.controller.BaseController;
import com.ruihu.admin.common.domain.ResponseDTO;
import com.ruihu.admin.common.domain.ValidateList;
import com.ruihu.admin.constant.ElectricConfigTypeEnum;
import com.ruihu.admin.module.business.electric.config.domain.dto.ElectricConfigAddDTO;
import com.ruihu.admin.module.business.electric.config.domain.dto.ElectricConfigUpdateDTO;
import com.ruihu.admin.module.business.electric.config.domain.dto.ElectricConfigQueryDTO;
import com.ruihu.admin.module.business.electric.config.domain.vo.ElectricConfigVO;
import com.ruihu.admin.module.business.electric.config.domain.vo.ElectricConfigExcelVO;
import com.ruihu.admin.module.business.electric.config.domain.vo.ElectricTypeVO;
import com.ruihu.admin.module.business.electric.config.service.ElectricConfigService;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import org.apache.poi.ss.usermodel.Workbook;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * [ 电芯型号维护表 ]
 *
 * @author Tony
 * @version 1.0
 * @company 瑞虎（南京）信息技术有限公司
 * @copyright (c)  瑞虎（南京）信息技术有限公司Inc. All rights reserved.
 * @date 2022-12-28 12:14:15
 * @since JDK1.8
 */
@RestController
@Api(tags = {"电芯配置维护"})
@OperateLog
public class ElectricConfigController extends BaseController {

    @Autowired
    private ElectricConfigService electricConfigService;

    @ApiOperation(value = "分页查询电芯型号维护表",notes = "@author Tony")
    @PostMapping("/electricConfig/page/query")
    public ResponseDTO<PageResultDTO<ElectricConfigVO>> queryByPage(@RequestBody ElectricConfigQueryDTO queryDTO) {
        //queryDTO.setConfigType(ElectricConfigTypeEnum.ELECTRIC_CORE_TYPE_CONFIG.getCode());
        return electricConfigService.queryByPage(queryDTO);
    }

    @ApiOperation(value = "查询电芯型号",notes = "@author Tony")
    @GetMapping("/electricConfig/queryElectricType")
    public ResponseDTO<List<ElectricTypeVO>> queryElectricType() {
        return electricConfigService.queryElectricConfig(ElectricConfigTypeEnum.ELECTRIC_CORE_TYPE_CONFIG);
    }

    @ApiOperation(value = "添加电芯型号维护表",notes = "@author Tony")
    @PostMapping("/electricConfig/add")
    public ResponseDTO<String> add(@RequestBody @Validated ElectricConfigAddDTO addTO){
        return electricConfigService.add(addTO);
    }

    @ApiOperation(value="修改电芯型号维护表",notes = "@author Tony")
    @PostMapping("/electricConfig/update")
    public ResponseDTO<String> update(@RequestBody @Validated ElectricConfigUpdateDTO updateDTO){
        return electricConfigService.update(updateDTO);
    }

    @ApiOperation(value="删除电芯型号维护表",notes = "@author Tony")
    @GetMapping("/electricConfig/deleteById/{electricConfigId}")
    public ResponseDTO<String> deleteById(@PathVariable Long electricConfigId) {
        return electricConfigService.deleteById(electricConfigId);
    }

    @ApiOperation(value="批量删除电芯型号维护表",notes = "@author Tony")
    @PostMapping("/electricConfig/deleteByIds")
    public ResponseDTO<String> delete(@RequestBody @Validated ValidateList<Long> idList) {
        return electricConfigService.deleteByIds(idList);
    }

    @ApiOperation(value = "批量导出", notes = "@author Tony")
    @PostMapping("/electricConfig/export/batch")
    public void batchExport(@RequestBody @Validated ValidateList<Long> idList, HttpServletResponse response) {
        //查询数据
        List<ElectricConfigExcelVO> electricConfigList = electricConfigService.queryBatchExportData(idList);
        //导出操作
        ExportParams ex = new ExportParams("电芯型号维护表", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, ElectricConfigExcelVO.class, electricConfigList);
        downloadExcel("电芯型号维护表", workbook, response);
    }

    @ApiOperation(value = "导出全部", notes = "@author Tony")
    @PostMapping("/electricConfig/export/all")
    public void exportAll(@RequestBody @Validated ElectricConfigQueryDTO queryDTO, HttpServletResponse response) {
        //查询数据
        List<ElectricConfigExcelVO> electricConfigList = electricConfigService.queryAllExportData(queryDTO);
        //导出操作
        ExportParams ex = new ExportParams("电芯型号维护表", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, ElectricConfigExcelVO.class, electricConfigList);
        downloadExcel("电芯型号维护表", workbook, response);
    }

}
